﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Citi.HeadCount.Domain;
using Citi.HeadCount.WebUI.Models;
using Citi.HeadCount.Domain.Repository;

namespace Citi.HeadCount.WebUI.Controllers
{
    public class TypeResultController : Controller
    {
        private TypeResultRepository TypeResultRepository { get; set; }

        public TypeResultController()
        {
            TypeResultRepository = new TypeResultRepository();
        }

        public ActionResult Delete(int id)
        {
            TypeResultRepository.Inative(id);

            return RedirectToAction("Index");
        }

        public ActionResult Index()
        {
            var modelList = TypeResultRepository.GetAll().ToList();
            return View(TypeResultViewModel.CreateModel(modelList));
        }

        public ActionResult Create()
        {
            FillViewBag();
            return View();
        }

        private void FillViewBag()
        {
            ViewBag.TypeRuleTypes = new TypeResultType().ToSelectList(true, true, "-");
        }

        [HttpPost]
        public ActionResult Create(TypeResultViewModel model)
        {
            try
            {
                TypeResultRepository.Save(TypeResultViewModel.CreateDomain(model));
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
